
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css"/>
		<style>
			.title{
				margin: 20px 15px 7px;
				color: #6d6d72;
				font-size: 15px;
			}
			
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">在线沟通</h1>
		</header>
		<div class="mui-content">
			<div class="title">
				消息列表
			</div>
			<ul class="mui-table-view" id="msglist">
				 <!--<li class="mui-table-view-cell">Item 1</li>
		         <li class="mui-table-view-cell">Item 2</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>
		         <li class="mui-table-view-cell">Item 3</li>-->
			</ul>
			<div class="mui-input-row" style="margin: 10px 5px;display:none;" id="textdiv">
					<textarea id="textareas" rows="5" placeholder="说两句..."></textarea>
			</div>
			
			<button id="send" onclick="sends()" type="button" class="mui-btn mui-btn-success mui-btn-block">我要回复</button>
			<button id="send1" onclick="sends1()" type="button" style="display: none;" class="mui-btn mui-btn-success mui-btn-block">发送</button>
			
		</div>
	</body>
	<script type="text/javascript" src="script/jquery-3.3.1.min.js"></script>
	<script src="js/mui.min.js"></script>
	<script src="js/app.js"></script>
	<script src="js/mui.js"></script>
	<script type="text/javascript">
		/*mui.init({
			swipeBack:true //启用右滑关闭功能
		});*/ 
		var portid = window.localStorage.getItem('portid1');
		var porttype = window.localStorage.getItem('porttype1');
		var receiverid = window.localStorage.getItem('adduserid1');
		var receivername = window.localStorage.getItem('nickname1');
		var porttitle = window.localStorage.getItem('porttitle1');
		var senderid = window.localStorage.getItem('id');
		var sendername = window.localStorage.getItem('nickname');
		
		(function($, doc) {
					$.init();
					$.plusReady(function() {
						console.log(portid+"--"+porttype+"--"+receiverid+"--"+receivername+"--"+porttitle);
//						window.localStorage.removeItem('portid1');
//						window.localStorage.removeItem('porttype1');
//						window.localStorage.removeItem('adduserid1');
//						window.localStorage.removeItem('nickname1');
//						window.localStorage.removeItem('porttitle1');
//						document.getElementById('textdiv').style.display="none"; 
						var url = servicePath+"sechandcar/app/sendmsg/selectCarByPortidAndPorttype";
						mui.ajax(url, {
							data: {portid:portid,porttype:porttype}, //把json转换为字符串
							dataType: 'json', //返回数据格式
							type: 'get', //请求方式
							async: false, 
							success: function(data) {
								for (var i=0;i<data.length;i++) {
									var li = '';
									li += '<li class="mui-table-view-cell">'+data[i].sendername+':'+data[i].msgcontent+'</li>';
									document.getElementById('msglist').innerHTML += li;
								}
							}
						});	
					});
				}
				(mui, document));
				
				function sends(){
					document.getElementById('textdiv').style.display="block"; 
					document.getElementById('send').style.display="none"; 
					document.getElementById('send1').style.display="block"; 
				}
				
				function sends1(){
					if($('#textareas').val()==''){
						alert('消息内容不能为空');
						$('#textareas').focus();
						return;
					}
					
					var url = servicePath+"sechandcar/app/sendmsg/saveappmsg";
					$.ajax(url, {
							data: 
							{
								portid:portid,
								porttype:porttype,
								senderid:senderid,
								sendername:sendername,
								receiverid:receiverid,
								receivername:receivername,
								porttitle:porttitle,
								msgcontent:$('#textareas').val(),
								readflag:'0'
								
							}, 
							dataType: 'json', //返回数据格式
							type: 'get', //请求方式
							async: false, 
							success: function(data) {
								if(data=='success'){
									alert('发送成功');
								}else{
									alert('发送失败');
								}
								window.history.back(-1);
								/*for (var i=0;i<data.length;i++) {
									var li = '';
									li += '<li class="mui-table-view-cell">'+data[i].sendername+':'+data[i].content+'</li>';
									document.getElementById('msglist').innerHTML += li;
								}*/
							}
						});	
				}
		
	</script>
</html>